﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;

using EMailClient;
using RISMOTAXDP.EmailService;
using System.Text.RegularExpressions;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
 
            RunTest1();

        }


        static void RunTest1()
        {
            EmailService instance = new EmailService();
            instance.ConsoleStart();
            Console.ReadLine();
            instance.ConsoleStop();
            Console.ReadLine();

        }


        static void RunTest2()
        {
            string SMTPAddress = "smtp.sina.net";
            string username = "support@taxmarks.com";
            string password = "tax02";

            SMTPClient smtpClient = new SMTPClient(SMTPAddress, username, password);
            try
            {
              bool result =   smtpClient.Connect() && smtpClient.AuthLogin();
              Console.WriteLine(result);
                smtpClient.Noop();
               
               
                EMail testMail = new EMail();
                testMail.From = "support@taxmarks.com";
                testMail.To = "daiy@cacshanghai.com";
                testMail.Subject = "3收件人测试邮件3";

                string htmlBody = @"<a href='http://ifwnewsletters.newsletters.infoworld.com/t/8326342/1198226470/635390/0/' style='font-size: 12px;' target='_blank'>Adopt the cloud, kill your IT career</a>";
                testMail.IsBodyHtml = true;
                testMail.Body = htmlBody;
                //testMail.Body = "此邮件分发给三个人.隐藏接收人\r\n邮件正文\r\nMAIL BODY\r\n";

                smtpClient.SendMail(testMail, false);
               

                smtpClient.Close();
                Console.ReadLine();
            }
            catch(Exception ex)
            {
                smtpClient.Close();
                Console.WriteLine(ex);
                Console.ReadLine();
            }

        }

        static void RunTest3()
        {
            string str1 = "aa@aa.com|2|3|4|5";

            string[] parameterCode = UtilHelper.SplitString(str1.Trim(), "|");

            Console.WriteLine(parameterCode.Length);
            Console.ReadLine();


        }

        static void RunTest4()
        {
            string s1 = @"<tr><td font=red>2009-1-2</td><td font=red>200</td><td>110</td></tr>

<tr><td>2009-1-3</td><td>200</td><td>110</td></tr>

<tr><td font=blue>2009-1-4</td><td>200</td><td>110</td></tr>";

            string s2 = @"<span>test</span>a1a2a3a4<span>test</span>[templateDate]<a href=\'http://www.lexiscn.com/latest_message.php?id=68810\' target='_blank' >多部委联合发布《关于鼓励和引导民间投资进入物流领域的实施意见》</a>&nbsp;&nbsp;[2012-06-11]
						<br>6月8日，国家发展改革委、公安部、财政部等部委联合公布了《关于鼓励和引导民间投资进入物流领域的实施意见》(《意见》)。
《意见》提[/templateDate] a5a6a7a8
<span>test</span><span>test</span>[templateDate]1234[/templateDate]";


            string st = RegStr(s1);
            Console.WriteLine("st:" + st);
            Console.WriteLine("--------------");
            string st2 = RegStr2(s2);
            Console.WriteLine("st2:" + st2);
            Console.ReadLine();
        
        }

        public static string RegStr(string objStr)
        {
            string returnStr = "";
            MatchCollection ml = Regex.Matches(objStr, "<tr>.*?</tr>");

 
            foreach (Match m in ml)
            {
                Console.WriteLine("m.Groups[0].tostring(): " + m.Groups[0].ToString());
                Console.WriteLine("m:"+ m.Value);
                string str = m.Value.Replace("</td></tr>", ",");
                Console.WriteLine(str);
                str = str.Replace("</td>", "|");
                Console.WriteLine(str);
                str = Regex.Replace(str, "<.*?>", "");
                Console.WriteLine(str);
                returnStr += str;
            }
 

            return returnStr;
        }

        public static string RegStr2(string objStr)
        {
            string returnStr = "";
            MatchCollection ml = Regex.Matches(objStr,  @"\s*\[templateDate\]([\s\S]+?)\[\/templateDate\]\s*");

            foreach (Match m in ml)
            {
                Console.WriteLine("m.Groups[0].tostring(): " + m.Groups[0].ToString());
               
                string str = m.Value;

                Console.WriteLine("m:" + str);
                //returnStr += str;
            }
            /*
            foreach (Match m in ml)
            {
                string str = m.Value.Replace("</td></tr>", ",");
                str = str.Replace("</td>", "|");
                str = Regex.Replace(str, "<.*?>", "");
                returnStr += str;
            }
            */

            return returnStr;
        }


        static void RunTest5()
        {
            string s1 = @"<span>test</span>a1a2a3a4<span>test</span>[templateRepeatList]<a href=\'$LawCaseTitleURL$\' target='_blank' >[$LawCaseWriter$]$LawCaseTitle$</a>&nbsp;&nbsp;[$LawCaseDate$]
						<br>6月8日，国家发展改革委、公安部、财政部等部委联合公布了《关于鼓励和引导民间投资进入物流领域的实施意见》(《意见》)。
《意见》提[/templateRepeatList] a5a6a7a8
<span>test</span><span>test</span>[templateRepeatList]1234[/templateRepeatList]";

            string s2 = "";


            Match m;

            m = MailTemplateObject.regex_RepeatList.Match(s1);

            if (m.Success)
            {
                Console.WriteLine("yes");
                Console.WriteLine("m.Groups[0]: " + m.Groups[0].ToString());// 符合条件的区块
                Console.WriteLine("m.Groups[1]: " + m.Groups[1].ToString());// 符合条件的区块（不包含条件本身）
            }
            else
            {
                Console.WriteLine("no");
            }

            /*
            for (m = MailTemplateObject.regex_RepeatList.Match(s1); m.Success; m = m.NextMatch())
            {
                Console.WriteLine("m.Groups[0]: " + m.Groups[0].ToString());// 符合条件的区块
                Console.WriteLine("m.Groups[1]: " + m.Groups[1].ToString());// 符合条件的区块（不包含条件本身）
                Console.WriteLine("---------");
            }
             */


            Console.WriteLine("");
            Console.ReadLine();
        }

        static void RunTest6()
        {
            string IDs = "1,2,3,4,";
            string _char = IDs.Substring((IDs.Length - 1), 1);
            if (_char == ",")
            {
                IDs = IDs.Substring(0, (IDs.Length - 1));
            }
            Console.WriteLine(IDs);
            Console.ReadLine();
        }
    }
}
